package mop.model.resource.filter;

import java.sql.Timestamp;
import java.util.LinkedList;
import java.util.List;

import mop.model.resource.ReservationInterface;
import mop.util.filter.Filter;

/**
 * Filter for reservations. Filters reservation based on start date
 * @author MOP Team 7
 */
public class ReservationStartFilter implements Filter<ReservationInterface>{
	/**
	 * Constructor
	 * @param start	Start we want to filter
	 * @effect Start is set
	 * 	|setStart(start)
	 */
	public ReservationStartFilter(Timestamp start){
		setStart(start);
	}
	
	/**
	 * The start we want to filter 
	 */
	private Timestamp start;
	
	/**
	 * Set start value we want to filter
	 * @param start
	 * @post Start is set to given value
	 * 	|getStart() == start
	 */
	public void setStart(Timestamp start){
		if(start == null)
			throw new IllegalArgumentException("Start is not defined in reservation start filter");
		
		this.start = start;
	}
	
	/**
	 * Return start filter value
	 * @return this.start
	 */
	public Timestamp getStart(){
		return this.start;
	}
	
	/**
	 * @see Filter#filter(List)
	 */
	@Override
	public List<ReservationInterface> filter(List<ReservationInterface> list) {
		List<ReservationInterface> copy = new LinkedList<ReservationInterface>();
		
		for(ReservationInterface r : list)
		{
			if(r.getStart().getTime() >= getStart().getTime()) 
				copy.add(r);
		}
			
		return copy;
	}

}
